import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)
const CHANGE = 'change';

export default new Vuex.Store({
  state: {
    uid:'',
    token:'',
    userInfo:{},
    // a:1
    isLogin:false
  },
  getters: {
  },
  mutations: {
    change(state,val){
      state.a= val
    },
    [CHANGE](state,{key,value}){
      state[key] = value
    },
    clear(state){
      state.uid = '';
      state.token = '';
      state.userInfo = {};
      state.isLogin = false;
    }
    // change(state,val){
    //   state.a=val
    // }
  },
  actions: {
    getUserInfo(json,token){
      console.log(json)

      getUserInfo({
        token
      }).then(res=>{
        console.log(res)

        json.commit('change',{key:"userInfo",value:res.data.userInfo})
        json.commit('change',{key:"uid",value:res.data.uid})
        json.commit('change',{key:"token",value:res.data.token})
        json.commit('change',{key:"isLogin",value:isLogin})
      })
    }
  },
  modules: {
  }
})
